﻿using System;
using System.Diagnostics;

namespace Modbus
{
	/// <summary>
	/// 
	/// </summary>
	internal static class Ensure
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="paramName"></param>
		/// <param name="actualValue"></param>
		/// <param name="minValue"></param>
		/// <param name="maxValue"></param>
		/// <exception cref="ArgumentOutOfRangeException"></exception>
		internal static void ArgumentInRange(string paramName, int actualValue, int minValue, int maxValue)
		{
			Debug.Assert(minValue <= maxValue, "minValue <= maxValue");

			if ((actualValue < minValue) || (actualValue > maxValue))
			{
				// TODO: Insert exception message.
				throw new ArgumentOutOfRangeException(paramName, actualValue, "");
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="paramName"></param>
		/// <param name="value"></param>
		/// <param name="comparand"></param>
		/// <exception cref="ArgumentException"></exception>
		internal static void ArgumentNotEqualTo(string paramName, byte value, byte comparand)
		{
			if (value == comparand)
			{
				// TODO: Insert exception message.
				throw new ArgumentException("", paramName);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="paramName"></param>
		/// <param name="array"></param>
		/// <param name="minLength"></param>
		/// <param name="maxLength"></param>
		/// <exception cref="ArgumentNullException"></exception>
		/// <exception cref="ArgumentException"></exception>
		internal static void ArrayOfRequiredLength(string paramName, Array array, int minLength, int maxLength)
		{
			Debug.Assert(minLength >= 0, "minLength >= 0");
			Debug.Assert(minLength <= maxLength, "minLength <= maxLength");

			if (array == null)
			{
				throw new ArgumentNullException(paramName);
			}
			if ((array.Length < minLength) || (array.Length > maxLength))
			{
				// TODO: Insert exception message.
				throw new ArgumentException("", paramName);
			}
		}
	}
}
